libxenlight: remove ctx dangerously passed to children
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:06:12 +0000 (07:06 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:06:12 +0000 (07:06 +0000)
apart from ctx->waitpid, it's potentially harmful to call into
logging.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.h

index 36e72cf3e0bd1fc4c5230a7fe7d97b4a4c92fa5f..df3ddc0708b16d4f384bd0432b01264d92b48fe0 100644 (file)
@@ -726,8 +726,8 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
     return (char **) flexarray_contents(dm_args);
 }
 
-void dm_xenstore_record_pid(struct libxl_ctx *ctx, void *for_spawn,
-                            pid_t innerchild) {
+void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild)
+{
     struct libxl_device_model_starting *starting = for_spawn;
     char *kvs[3];
     int rc;
index 011ed8452db658d47b8cc1af497af66b3e7a9c46..e8cc74c7dac3c1ea1c0d28aeb775042234ccc65e 100644 (file)
@@ -100,8 +100,7 @@ void libxl_report_child_exitstatus(struct libxl_ctx *ctx,
 int libxl_spawn_spawn(struct libxl_ctx *ctx,
                       libxl_device_model_starting *starting,
                       const char *what,
-                      void (*intermediate_hook)(struct libxl_ctx *ctx,
-                                                void *for_spawn,
+                      void (*intermediate_hook)(void *for_spawn,
                                                 pid_t innerchild))
 {
     pid_t child, got;
@@ -127,18 +126,19 @@ int libxl_spawn_spawn(struct libxl_ctx *ctx,
 
     /* we are now the intermediate process */
 
-    child = libxl_fork(ctx);
-    if (!child) return 0; /* caller runs child code */
-    if (child < 0) exit(255);
+    child = fork();
+    if (child == -1)
+        exit(255);
+    if (!child)
+        return 0; /* caller runs child code */
 
-    intermediate_hook(ctx, starting, child);
+    intermediate_hook(starting, child);
 
     if (!for_spawn) _exit(0); /* just detach then */
 
     got = call_waitpid(ctx->waitpid_instead, child, &status, 0);
     assert(got == child);
 
-    libxl_report_child_exitstatus(ctx, what, child, status);
     _exit(WIFEXITED(status) ? WEXITSTATUS(status) :
           WIFSIGNALED(status) && WTERMSIG(status) < 127
           ? WTERMSIG(status)+128 : -1);
index 14952ca62968b6a60d8eff67ed2260446cc33c12..7664e592f724263bd19ff01cff06fbfcbbead3d1 100644 (file)
@@ -181,9 +181,7 @@ struct libxl_device_model_starting {
 int libxl_spawn_spawn(struct libxl_ctx *ctx,
                       libxl_device_model_starting *starting,
                       const char *what,
-                      void (*intermediate_hook)(struct libxl_ctx *ctx,
-                                                void *for_spawn,
-                                                pid_t innerchild));
+                      void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
   /* Logs errors.  A copy of "what" is taken.  Return values:
    *  < 0   error, for_spawn need not be detached
    *   +1   caller is now the inner child, should probably call libxl_exec